//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#if !defined (__KEYSOUND_H__)
#define __KEYSOUND_H__

#define CTRL_OPEN_KEYSOUND      0x01
#define CTRL_CLOSE_KEYSOUND     0x03

#define CTRL_OPEN_TOUCHSOUND    0x02
#define CTRL_CLOSE_TOUCHSOUND   0x04

#define CTRL_SET_PLAYSOUND      0x10
#define CTRL_SET_PLAYVOLUME     0x20

typedef enum
{
    IDLE=0,
    BUSY,
    STOP,
} PlayState;

typedef struct
{
    int siz;
    void *buf;
} BYTEBUF;

class CPlaySound : public CDeviceDriver
{
public:
    CARAPI Read(
        /* [in] */ Int64 u64Offset,
        /* [in] */ Int32 bytesToRead,
        /* [out] */ MemoryBuf * pBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Write(
        /* [in] */ Int64 u64Offset,
        /* [in] */ const MemoryBuf & buffer,
        /* [out] */ Int32 * pBytesWritten,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Control(
        /* [in] */ _ELASTOS Handle32 nControlCode,
        /* [in] */ const MemoryBuf & inBuffer,
        /* [out] */ MemoryBuf * pOutBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    virtual void Dispose();
    ECode Initialize();
    ECode PlaySound();
public :
    IDeviceDriver *m_pAudio;
    IDeviceDriver *m_pQueues;
    PlayState m_State; //Device driver state
    int     m_tracknum;
    _ELASTOS UInt16  m_volume;
#define _MAX_KEY    15
    BYTEBUF m_RawArr[_MAX_KEY+1];
};

#endif
